package server.startup;

import server.*;
import server.core.StandardWrapper;

public class Context2Config implements LifecycleListener {
    @Override
    public void lifecycleEvent(LifecycleEvent event) {
        if (Lifecycle.START_EVENT.equals(event.getType())) {
            Context context = (Context)event.getLifecycle();
            configServlet(context);
            //设置配置成功
            context.setConfigured(true);
        }
    }
    private void configServlet(Context context) {
        Wrapper wrapper2 = new StandardWrapper();
        wrapper2.setName("wrapper2");
        wrapper2.setServletClass("App2Wrapper2Test");


        Wrapper wrapper1 = new StandardWrapper();
        wrapper1.setName("S1");
        wrapper1.setServletClass("S1");

        Wrapper wrapper3 = new StandardWrapper();
        wrapper3.setName("error");
        wrapper3.setServletClass("Error");

        Wrapper wrapper4 = new StandardWrapper();
        wrapper4.setName("d");
        wrapper4.setServletClass("DownLoad");

        context.addChild(wrapper2);
        context.addChild(wrapper1);
        context.addChild(wrapper3);
        context.addChild(wrapper4);

        context.addServletMapping("/a2", "wrapper2");
        context.addServletMapping("/s1", "S1");
        context.addServletMapping("/error", "error");
        context.addServletMapping("/d", "d");


    }
}
